package com.example.demo;

import java.util.List;
import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.model.CustomBean;
import com.example.demo.service.TestService;
import com.youxin.foundation.utils.ConfigurationUtils;

/**
 * 
 * @author yingde.cao
 *
 */
@RestController
public class EsController {
	 

	
	@Autowired
    private TestService testService;
	
	@RequestMapping("/es")
    public String testES() {
		testService.init();
    	Properties properties=ConfigurationUtils.getProperties("kafka.properties");
    	
    	//new java.lang.Thread(new KafkaProducerTask(properties, new ProducerRecord<String,String>("test", "testKey", "My Kafka:"+new Date().toString()))).start();;
    	return "es init";
	}
	
	@RequestMapping(value="/q",produces="application/json")
	public List<com.example.demo.model.News> searchEs(@RequestParam String title)
	{
		return testService.search(title);
	}
	
	@RequestMapping(value="/d",produces="application/json")
	public List<com.example.demo.model.News> deleteEs(@RequestParam String id)
	{
		 testService.deleteAll(id);
		 return testService.findAll();
	}
	
	@RequestMapping(value="/espost",method = RequestMethod.POST ,produces="application/json")
	public List<com.example.demo.model.News> espost(@RequestBody CustomBean id)
	{
		 return testService.findAll();
	}
	
}
